//go:build ignore

package main

import (
	"fmt"
	"sync"
)

// 将一个字符串中的字母,数字分离,分别打印出来
// 最终打印效果:12AB34CD56EF78GH910IJ1112KL1314MN1516OP1718QR1920ST2122UV2324WX2526YZ2728
func main() {
	fmt.Println("pinterA result:")
	printerA()
	fmt.Println("printerB result:")
	printerB()
	fmt.Println()
	fmt.Println("printer finish!!!")
}

func printerA() {
	number := make(chan bool)
	letter := make(chan bool)
	done := make(chan bool)

	go func() {
		i := 1
		for {
			select {
			case <-number:
				fmt.Print(i)
				i++
				//fmt.Print(i)
				//i++
				letter <- true
			}
		}
	}()

	go func() {
		j := 'A'
		for {
			select {
			case <-letter:
				if j >= 'Z' {
					done <- true
				} else {
					fmt.Print(string(j))
					j++
					//fmt.Print(string(j))
					//j++
					number <- true
				}
			}
		}
	}()

	number <- true

	for {
		select {
		case <-done:
			return
		}
	}
}

func printerB() {
	letter, number := make(chan bool), make(chan bool)
	wait := sync.WaitGroup{}

	go func() {
		i := 1
		for {
			select {
			case <-number:
				fmt.Print(i)
				i++
				//fmt.Print(i)
				//i++
				letter <- true
			}
		}
	}()
	wait.Add(1)
	go func(wait *sync.WaitGroup) {
		i := 'A'
		for {
			select {
			case <-letter:
				if i >= 'Z' {
					wait.Done()
					return
				}

				fmt.Print(string(i))
				i++
				//fmt.Print(string(i))
				//i++
				number <- true
			}

		}
	}(&wait)
	number <- true
	wait.Wait()
}
